#include <stdio.h>

#define INT_MAX 2147483647
#define INT_MIN (-2147483647 - 1)  // 此处不能直接定义为 -2147483648

int reverse_number(int num);

int main(void)
{
    printf("%d\n", reverse_number(12345));
    printf("%d\n", reverse_number(1999999999));
    printf("%d\n", reverse_number(987654321));
    printf("%d\n", reverse_number(235543));
    printf("%d\n", reverse_number(1234567899));
    return 0;
}


/* 求出一个整型数的倒序数 */
int reverse_number(int num) {
    long long reversed = 0LL;  // 存储倒序后的数字
    while (num) {
        reversed = reversed * 10 + (num % 10);  // 将其加到结果的末尾
        num /= 10;  // 删除数字的最后一位
    }
    if (reversed > INT_MAX || reversed < INT_MIN) {
        printf("反转后数据溢出！！！\n");
        return 0; 
    }

    return (int)reversed;
}
